﻿using System;
using System.Collections.Generic;
using System.Linq;
using JL.LiveAtEdu.Helpers;
using System.IO;

namespace JL.LiveAtEdu.Portal
{
    public partial class SendMessage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LinkButtonSend_OnClick(object sender, EventArgs e)
        {
            Bind.MyLiveUser = TxtFrom.Text;
            Bind.MyLivePassword = TxtPassword.Text;

            try
            {   
                List<string> lstTO = new List<string>();
                List<string> lstCC = new List<string>();
                List<string> lstBCC = new List<string>();
                List<string> lstATT = new List<string>();

                //You can foreach in order to add a colletion
                lstTO.Add(TxtTo.Text);
                lstCC.Add(TxtCC.Text);
                lstBCC.Add(TxtBCC.Text);
                if (FileUploadAtt.HasFile)
                {
                    string filename = Path.GetFullPath(FileUploadAtt.PostedFile.FileName);
                    lstATT.Add(filename);
                }
                Messages.SendNewMessage(Bind.MeIn(), TxtSubject.Text, TxtBody.Text, lstTO, lstCC, lstBCC, lstATT);
                LiteralMess.Text = "Message has been sent.!";
            }
            catch (Exception ex)
            {
                LiteralMess.Text = ex.Message;
            }
        }
    }
}